﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.DAL;
using rock.common;
using rock.UI.common;
using rock.BLL;
using rock.UI.houseinfo;

namespace rock.UI.message
{
    public partial class UserControlMessageContract : UserControl
    {
        DalRENT_CONTRACT aDalRENT_CONTRACT = new DalRENT_CONTRACT();
        BllRENT_CONTRACT aBllRENT_CONTRACT = new BllRENT_CONTRACT();
        DalRENT_CUSTOM aDalRENT_CUSTOM = new DalRENT_CUSTOM();
        int CURRENT_NOTIFY_DAY = 0;
        public UserControlMessageContract()
        {
            InitializeComponent();
            this.Dock = System.Windows.Forms.DockStyle.Fill;
            ViewUtils.setDataGridViewStlye(this.dataGridView1);
        }

        private void UserControlMessageContract_Load(object sender, EventArgs e)
        {
            CURRENT_NOTIFY_DAY = 0; 
            refreshData(0);
        }

        private void radioButton0_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioButton0.Checked)
            {
                return;
            }
            CURRENT_NOTIFY_DAY = 0; 
            refreshData(0);
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioButton3.Checked)
            {
                return;
            }
            CURRENT_NOTIFY_DAY = 3; 
            refreshData(3);
        }

        private void radioButton7_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioButton7.Checked)
            {
                return;
            }
            CURRENT_NOTIFY_DAY = 7; 
            refreshData(7);
        }

        private void radioButton15_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioButton15.Checked)
            {
                return;
            }
            CURRENT_NOTIFY_DAY =15; 
            refreshData(15);
        }

        private void radioButton30_CheckedChanged(object sender, EventArgs e)
        {
            if (!radioButton30.Checked)
            {
                return;
            }
            CURRENT_NOTIFY_DAY = 30; 
            refreshData(30);
        }


        private void refreshData(int notifyDate) {
            DataSet ds = aDalRENT_CONTRACT.GetContractNotifyMessage(CURRENT_NOTIFY_DAY);
            this.dataGridView1.DataSource = ds.Tables[0]; 
        }
        //查看用户信息
        private void button3_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                String seqid = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["CUSTOM_SEQID"].Value.ToString();
                // this.textBox1.Text = value;
                FormRentCustomUpdate fcv = new FormRentCustomUpdate();
                 
                fcv._ModelRENT_CUSTOM = aDalRENT_CUSTOM.GetModel(Convert.ToInt32(seqid));
                //注册代理
                fcv.oneRefreshParentData = refreshData;
                fcv.ShowDialog(this);
            }
            else
            {
                MessageBox.Show("请选择要查看的记录.", "提示");
            }
        }
        //终止合同
        private void button1_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                String seqid = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["CONTRACT_SEQID"].Value.ToString();

                //String status = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["STATUS_INT"].Value.ToString();
                //if (Convert.ToInt32(status) != Constant.RENT_CONTRACT_STATUS_SHENGXIAO)
                //{
                //    MessageBox.Show("此合同已经不在执行,不需终止.");
                //    return;
                //}

                int seqidInt = Convert.ToInt32(seqid);
                if (seqidInt > 0)
                {


                    DialogResult dialogResult = MessageBox.Show("请确认是否要将选择的终止合同?终止合同前请处理完押金与房租及其它费用.合同一量终止.所有操作都将冻结.", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

                    if (dialogResult.Equals(DialogResult.OK))
                    {
                        aBllRENT_CONTRACT.DongzhiContract(seqidInt);
                        //dal.Delete(seqidInt);
                        //刷新数据
                        refreshData(CURRENT_NOTIFY_DAY);
                    }


                }
            }
            else
            {
                MessageBox.Show("请选择要终止的记录.", "提示");
            }  
        }
        //继期合同
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {

                String seqid = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["CONTRACT_SEQID"].Value.ToString();
                // this.textBox1.Text = value;
                FormRentContractUpdate fcv = new FormRentContractUpdate();
                fcv._ModelRENT_CONTRACT = aDalRENT_CONTRACT.GetModel(Convert.ToInt32(seqid));
                //注册代理
                fcv.oneRefreshParentData = refreshData;
                fcv.ShowDialog(this);

            }
            else
            {
                MessageBox.Show("请选择要继期的记录.", "提示");
            }
        }
        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                row.Cells[0].Value = row.Index + 1;
            }
        }
    }
}
